package com.moli.iov.protocol.codec;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;
import java.util.Map;
import org.apache.kafka.common.serialization.Deserializer;

/**
 * <p>
 *
 * </p>
 *
 * @author zql
 * @since 2019/10/18 15:42
 */
public class ObjectDeserializer implements Deserializer<Object> {

  @Override
  public void configure(Map<String, ?> configs, boolean isKey) {

  }

  @Override
  public Object deserialize(String topic, byte[] data) {
    Object object = null;

    try {
      ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
      ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
      object = objectInputStream.readObject();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return object;
  }

  @Override
  public void close() {

  }
}
